qcollect-traits 0.6.0

Traits for being generic over collection-types.
use std::collections::Bound;
use std::ops::{Range, RangeFrom, RangeFull, RangeTo};

/// NOTE the official Range-api is still very much in flux, but this works for now.
pub trait RangeArgument<T> {
    fn into_bounds(self) -> (Bound<T>, Bound<T>);
}

impl<T> RangeArgument<T> for (Bound<T>, Bound<T>) {
    fn into_bounds(self) -> (Bound<T>, Bound<T>) { self }
}

impl<T> RangeArgument<T> for Range<T> {
    fn into_bounds(self) -> (Bound<T>, Bound<T>) {
        (Bound::Included(self.start), Bound::Excluded(self.end))
    }
}

impl<T> RangeArgument<T> for RangeFrom<T> {
    fn into_bounds(self) -> (Bound<T>, Bound<T>) {
        (Bound::Included(self.start), Bound::Unbounded)
    }
}

impl<T> RangeArgument<T> for RangeFull {
    fn into_bounds(self) -> (Bound<T>, Bound<T>) {
        (Bound::Unbounded, Bound::Unbounded)
    }
}

impl<T> RangeArgument<T> for RangeTo<T> {
    fn into_bounds(self) -> (Bound<T>, Bound<T>) {
        (Bound::Unbounded, Bound::Excluded(self.end))
    }
}